package jdbcEx.examples;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCExaMPLE {

	public static void main(String[] args) {

		Connection connection = null;
		Statement statement = null;
		ResultSet resultSet = null;

		String SQL_STATMENT = "insert into  states (stateId,stateName) values ('AD','INDIA')";
		String SQL_STATMENT_SELECT = "SELECT * FROM STATES";
		try {
			// Load the driver

			Class.forName("com.mysql.jdbc.Driver");

			connection = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/explorecalifornia", "root",
					"root");
			statement = connection.createStatement();
			boolean result = statement.execute(SQL_STATMENT);

			if (result) {
				System.out.println(" Process Results here");

			} else {
				System.out.println(" Number of records updated is - "
						+ statement.getUpdateCount());
			}

		} catch (Exception exception) {

			System.out.println(" Error occured while Getting Data from DB"
					+ exception.getMessage());

		} finally {
			try {

				if (resultSet != null) {

					resultSet.close();
				}

				if (statement != null) {
					statement.close();
				}

				if (connection != null) {
					connection.close();
				}
			} catch (Exception exception2) {

				System.out.println(" Error occured while closeing resources"
						+ exception2.getMessage());
			}

		}

	}

}
